package cn.yi.newsys.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

public class CheckCodeServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		// 获取服务器端的 session 对象
		String str = (String)request.getSession().getAttribute("imgcode") ;
		// 获取用户填写的验证码
		String inputCode = request.getParameter("code") ;
		HashMap<String, String> map = new HashMap<String, String>() ;
		if(str.equalsIgnoreCase(inputCode)){
			map.put("result", "验证码正确") ;
		}else{
			map.put("result", "验证码不正确") ;
		}
		out.print(JSON.toJSON(map)) ;
		out.flush();
		out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doGet(request, response);
	}

}
